
package kaizone.haining.chaobohui.fragment;

import kaizone.haining.chaobohui.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class DetailWebFragment extends Fragment {

    public static final String WEB_FLAG = "web_flag";

    private String mUrl;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUrl = getArguments() != null ? getArguments().getString(WEB_FLAG) : "";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = (View) inflater.inflate(R.layout.detail_web, null);
        WebView webView = (WebView) view.findViewById(R.id.webview);
        webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setBuiltInZoomControls(true);
        settings.setSupportZoom(true);
        // settings.setUseWideViewPort(true);
        // settings.setLoadWithOverviewMode(true);

        settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.loadUrl(mUrl);
        return view;
    }

    public void setup(WebSettings settings) {
        settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    }

    public void setup2(WebSettings settings) {
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
    }

    public void setup3(WebSettings settings) {
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
    }

    public static DetailWebFragment newInstance(String flag) {
        final DetailWebFragment f = new DetailWebFragment();

        final Bundle args = new Bundle();
        args.putString(WEB_FLAG, flag);
        f.setArguments(args);

        return f;
    }

}
